/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.klikmee.sms.core.model;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 * 
 * @author makcro
 */
@Entity
@Table(name = "distributionlistitem")
@NamedQueries({
		@NamedQuery(name = "DistributionListItem.findAll", query = "SELECT d FROM DistributionListItem d"),
		@NamedQuery(name = "DistributionListItem.findById", query = "SELECT d FROM DistributionListItem d WHERE d.id = :id"),
		@NamedQuery(name = "DistributionListItem.findByPhoneNumber", query = "SELECT d FROM DistributionListItem d WHERE d.phoneNumber = :phoneNumber"),
		@NamedQuery(name = "DistributionListItem.findByNote", query = "SELECT d FROM DistributionListItem d WHERE d.note = :note"),
		@NamedQuery(name = "DistributionListItem.findByMtsServiceIdListIdAndMsisdn", query = "SELECT d FROM DistributionListItem d WHERE d.distributionList.service.mtsServiceId = :serviceId AND d.distributionList.listMTSId = :listId AND d.phoneNumber = :msisdn"),
		@NamedQuery(name = "DistributionListItem.deleteByMsisdn", query = "DELETE FROM DistributionListItem dli WHERE dli.phoneNumber = :msisdn")})
public class DistributionListItem implements Serializable {
	private static final long	serialVersionUID	= 1L;
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Basic(optional = false)
	@Column(name = "Id", nullable = false)
	private Long				id;
	@Column(name = "PhoneNumber", length = 64)
	private String				phoneNumber;
	@Column(name = "ValidTo")
	@Temporal(TemporalType.DATE)
	private Date				validTo;
	@Column(name = "Note", length = 512)
	private String				note;
	@JoinColumn(name = "DistributionListId", referencedColumnName = "Id")
	@ManyToOne
	private DistributionList	distributionList;

	public DistributionListItem() {
	}

	public Date getValidTo() {
		return validTo;
	}

	public void setValidTo( Date validTo ) {
		this.validTo = validTo;
	}

	public DistributionListItem( Long id ) {
		this.id = id;
	}

	public Long getId() {
		return id;
	}

	public void setId( Long id ) {
		this.id = id;
	}

	public String getPhoneNumber() {
		return phoneNumber;
	}

	public void setPhoneNumber( String phoneNumber ) {
		this.phoneNumber = phoneNumber;
	}

	public String getNote() {
		return note;
	}

	public void setNote( String note ) {
		this.note = note;
	}

	public DistributionList getDistributionList() {
		return distributionList;
	}

	public void setDistributionList( DistributionList distributionListId ) {
		this.distributionList = distributionListId;
	}

	@Override
	public int hashCode() {
		int hash = 0;
		hash += (id != null ? id.hashCode() : 0);
		return hash;
	}

	@Override
	public boolean equals( Object object ) {
		
		if (!(object instanceof DistributionListItem)) {
			return false;
		}
		DistributionListItem other = (DistributionListItem) object;
		if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals( other.id ))) {
			return false;
		}
		return true;
	}

	@Override
	public String toString() {
		return "com.klikmee.sms.core.model.DistributionListItem[ id=" + id + " ]";
	}

}
